/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package merlion.frm.bpm.entity;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Collection;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import merlion.common.entity.DocFile;
import merlion.scm.rmpm.entity.RawMaterialSalesOrder;
import merlion.scm.rmpm.entity.Supplier;
import merlion.scm.rmpm.entity.GoodsReceiptRating;
import merlion.scm.rmpm.entity.RawMaterialInventoryBatch;
import merlion.scm.rmpm.entity.RawMaterialItemLine;

/**
 *
 * @author Yuwei
 */
@Entity
public class SupplierInvoice implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String supplierInvoiceNo;
    private Timestamp dateCreated; 
    private Timestamp invoiceDueDate;
    private Double invoiceAmount;
    private Boolean currency;
    @OneToOne (targetEntity=SupplierPaymentRecord.class, cascade={CascadeType.ALL}, fetch=FetchType.EAGER)
    private SupplierPaymentRecord supplierPaymentRecord;
    @ManyToOne(targetEntity=Supplier.class, cascade={CascadeType.PERSIST,CascadeType.MERGE}, fetch=FetchType.EAGER)
    private Supplier supplier;
    @OneToOne(targetEntity = RawMaterialSalesOrder.class, cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch = FetchType.EAGER, mappedBy = "invoice")
    private RawMaterialSalesOrder rmso;
    @OneToOne(targetEntity = DocFile.class, cascade = {CascadeType.ALL}, fetch = FetchType.EAGER)
    private DocFile uploadedImage;
    @OneToMany(targetEntity=RawMaterialItemLine.class, cascade={CascadeType.PERSIST,CascadeType.MERGE}, fetch=FetchType.EAGER)
    private Collection<RawMaterialItemLine> itemLines;

    public SupplierInvoice(){
        supplierInvoiceNo = "";
        invoiceAmount = (double)0;
        supplierPaymentRecord = new SupplierPaymentRecord();
        dateCreated = new Timestamp(System.currentTimeMillis());
        itemLines = new ArrayList<RawMaterialItemLine>();
    }
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Double getInvoiceAmount() {
        return invoiceAmount;
    }

    public void setInvoiceAmount(Double invoiceAmount) {
        this.invoiceAmount = invoiceAmount;
    }

    public String getSupplierInvoiceNo() {
        return supplierInvoiceNo;
    }

    public void setSupplierInvoiceNo(String supplierInvoiceNo) {
        this.supplierInvoiceNo = supplierInvoiceNo;
    }

    public SupplierPaymentRecord getSupplierPaymentRecord() {
        return supplierPaymentRecord;
    }

    public void setSupplierPaymentRecord(SupplierPaymentRecord supplierPaymentRecord) {
        this.supplierPaymentRecord = supplierPaymentRecord;
    }

    public DocFile getUploadedImage() {
        return uploadedImage;
    }

    public void setUploadedImage(DocFile uploadedImage) {
        this.uploadedImage = uploadedImage;
    }

    public Timestamp getDateCreated() {
        return dateCreated;
    }

    public void setDateCreated(Timestamp dateCreated) {
        this.dateCreated = dateCreated;
    }

    public Supplier getSupplier() {
        return supplier;
    }

    public void setSupplier(Supplier supplier) {
        this.supplier = supplier;
    }

    public RawMaterialSalesOrder getRmso() {
        return rmso;
    }

    public void setRmso(RawMaterialSalesOrder rmso) {
        this.rmso = rmso;
    }

    public Collection<RawMaterialItemLine> getItemLines() {
        return itemLines;
    }

    public void setItemLines(Collection<RawMaterialItemLine> itemLines) {
        this.itemLines = itemLines;
    }

    public Boolean getCurrency() {
        return currency;
    }

    public void setCurrency(Boolean currency) {
        this.currency = currency;
    }

    public Timestamp getInvoiceDueDate() {
        return invoiceDueDate;
    }

    public void setInvoiceDueDate(Timestamp invoiceDueDate) {
        this.invoiceDueDate = invoiceDueDate;
    }
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof SupplierInvoice)) {
            return false;
        }
        SupplierInvoice other = (SupplierInvoice) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "merlion.frm.bpm.entity.SupplierInvoice[ id=" + id + " ]";
    }
    
}
